package IO_demo.objectStream;

import java.io.*;

/**
 * @author Summerday
 */
public class ObjectInputStreamExample {

    public static void main(String[] args) throws IOException, ClassNotFoundException {


        ObjectOutputStream objectOutputStream =
                new ObjectOutputStream(new FileOutputStream("user.txt"));

        User u = new User("summerday", 20);


        objectOutputStream.writeObject(u);
        objectOutputStream.close();

        User user;
        try (ObjectInputStream objectInputStream =
                     new ObjectInputStream(new FileInputStream("user.txt"))) {
            user = (User) objectInputStream.readObject();

        }
        System.out.println(user.getName());
        System.out.println(user.getAge());
    }

}
